package com.mvd.app.ac2021.activitys;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.kongzue.dialog.interfaces.OnMenuItemClickListener;
import com.kongzue.dialog.util.TextInfo;
import com.kongzue.dialog.v3.BottomMenu;
import com.kongzue.dialog.v3.MessageDialog;
import com.kongzue.dialog.v3.TipDialog;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.mvd.app.R;
import com.mvd.app.activity.BaseActivity;
import com.mvd.app.application.BaseApplication;
import com.mvd.app.commons.CommonUtils;
import com.mvd.app.commons.DateUtil;
import com.mvd.app.commons.JsonUtil;
import com.mvd.app.commons.PDALogUtils;
import com.mvd.app.commons.SharedPreferencesUtils;
import com.mvd.app.commons.UtilsLog;
import com.mvd.app.commons.VehicleCheckUtils;
import com.mvd.app.model.CarItemStartModel;
import com.mvd.app.model.CarsInforModel;
import com.mvd.app.model.CheckItemModel;
import com.mvd.app.model.UpdateCarInfoModel;
import com.mvd.app.model.WaiJianItemModel;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.iwgang.countuptime.LogUtils;

import static com.mvd.app.application.BaseApplication.checkItemModelList;

/**
 * 车辆详情 页面
 */

public class CarActivity extends BaseActivity {

    @BindView(R.id.ac_car_number)
    TextView acCarNumber;
    @BindView(R.id.ac_car_SN)
    TextView acCarSN;
    @BindView(R.id.ac_car_VIN)
    TextView acCarVIN;
    @BindView(R.id.ac_car_times)
    TextView acCarTimes;
    @BindView(R.id.ac_car_line)
    TextView acCarLine;
    @BindView(R.id.ac_car_lianwang)
    Button acCarLianwang;
    @BindView(R.id.ac_car_weiyixing)
    Button acCarWeiyixing;
    @BindView(R.id.ac_car_waijian)
    Button acCarWaijian;
    @BindView(R.id.ac_car_6m)
    Button acCar6m;
    @BindView(R.id.ac_car_waijian_luxiang_start)
    Button acCarWaijianLuxiangStart;
    @BindView(R.id.ac_car_bodycolor)
    TextView acCarBodycolor;
    @BindView(R.id.ac_car_luntaiguige)
    TextView acCarLuntaiguige;
    @BindView(R.id.ac_car_engineNumber)
    TextView acCarEngineNumber;
    @BindView(R.id.ac_car_lectronice_handbrake)
    TextView acCarLectroniceHandbrake;
    @BindView(R.id.ac_car_air_suspension)
    TextView acCarAirSuspension;
    @BindView(R.id.ac_car_suspension_form)
    TextView acCarSuspensionForm;
    @BindView(R.id.ac_car_mileage)
    EditText acCarMileage;
    @BindView(R.id.ac_car_btn_update)
    Button acCarBtnUpdate;
    @BindView(R.id.ac_car_more_info)
    TextView acCarMoreInfo;
    @BindView(R.id.ac_car_layout_moreInfo)
    LinearLayout acCarLayoutMoreInfo;
    @BindView(R.id.ac_car_beizhu)
    EditText acCarBeizhu;

    @BindView(R.id.ac_car_tv_beizhu_more)
    TextView acCarTvBeizhuMore;
    @BindView(R.id.ac_car_kongqi_xuanjia_zhou_shu)
    EditText acCarKongqiXuanjiaZhouShu;
    @BindView(R.id.ac_car_jianyi)
    EditText acCarJianYiEt;

    private int CHECK_MODE = 0;//检测模式 0:外检  1：路试 2：底盘动态
    private String Line = "1";//外检车道
    private String Item_Code = "";//F1外检,R1路试，DC底盘动态
    private String Login_name = "", login_IDNumber;//当前登录的检测员的名字
    private CarsInforModel carsInforModel;
    public CarActivity instances = null;
    public boolean NQ_STATEMENT = false;//判定按钮是否可点击  ---联网查询
    public boolean UC_STATEMENT = false;//判定按钮是否可点击  ---唯一性
    private boolean isMoreInfo = false; //false:更多 true:隐藏
    private boolean TianJin_Start = false;
    String EngineNOFlag,jianyi;
    private String dzss;
    WaiJianItemModel model = new WaiJianItemModel();
    boolean register_date_result;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_car);
        ButterKnife.bind(this);
        setBackBtn();
        setTopTitle("车辆详情");
        String logStrf = "\n" + "onCreate-----车辆详情-----CarActivity---" + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
        instances = this;

        carsInforModel = (CarsInforModel) getIntent().getSerializableExtra("model_CarsInforModel");
        login_IDNumber = getIntent().getExtras().getString("login_IDNumber", "");
        Login_name = getIntent().getExtras().getString("Login_name", "");
        CHECK_MODE = BaseApplication.JIANCE_MODE;
        initMoreInfo();
        switch (CHECK_MODE) {
            case 0:
                Item_Code = "F1";
                break;
            case 1:
                Item_Code = "R1";
                break;
            case 2:
                Item_Code = "DC";
                break;
        }
//region
        if (carsInforModel != null) {
            //驻车制动是否使用电子控制装置
            if (!TextUtils.isEmpty(String.valueOf(carsInforModel.getElectronicHandbrake()))) {
                acCarLectroniceHandbrake.setText(carsInforModel.getElectronicHandbrake().equals("1") ? "是" : "否");
            }

            String electronicHandbrake = acCarLectroniceHandbrake.getText().toString().trim();
            if (electronicHandbrake.contains("是")) {
                BaseApplication.DZSS = "是";
                dzss = "是";
            } else {
                BaseApplication.DZSS = "否";
                dzss = "否";
            }

            //发动机号
            acCarEngineNumber.setText(TextUtils.isEmpty(carsInforModel.getEngineNO()) ? "" : carsInforModel.getEngineNO());
            //轮胎规格
            if (!TextUtils.isEmpty(carsInforModel.getTyreSize())) {
                acCarLuntaiguige.setText(carsInforModel.getTyreSize());
            }

            //车牌号码
            if (!TextUtils.isEmpty(carsInforModel.getPlateRegion()) &&
                    !TextUtils.isEmpty(carsInforModel.getPlateNO())) {
                acCarNumber.setText(carsInforModel.getPlateRegion() +
                        carsInforModel.getPlateNO());
            }
            //检验次数```````
            if (!TextUtils.isEmpty(String.valueOf(carsInforModel.getTimes()))) {
                acCarTimes.setText(carsInforModel.getTimes() + "次");
            }
            //SN
            if (!TextUtils.isEmpty(String.valueOf(carsInforModel.getSN()))) {
                acCarSN.setText(carsInforModel.getSN());
            }
            //VIN
            if (!TextUtils.isEmpty(String.valueOf(carsInforModel.getVIN()))) {
                acCarVIN.setText(carsInforModel.getVIN());
            }

            //车身颜色
            if (!TextUtils.isEmpty(carsInforModel.getBodyColor())) {
                acCarBodycolor.setText(VehicleCheckUtils.CarColorsFilter(carsInforModel
                        .getBodyColor()));
            }
            //里程数
            if (!TextUtils.isEmpty(carsInforModel.getOdometer())) {
                acCarMileage.setText(carsInforModel.getOdometer());
            }
            //0 独立悬架  1  非独立悬架
            if (carsInforModel.getSuspensionForm().equals("1")) {
                acCarSuspensionForm.setText("非独立悬架");
            } else {
                acCarSuspensionForm.setText("独立悬架");
            }
        }
        List<WaiJianItemModel> books = WaiJianItemModel.listAll(WaiJianItemModel.class);
        if (books != null && books.size() > 0) {
            UtilsLog.e("CarActivity----本地数据库查询----不为空==" + books.toString());
            for (int i = 0; i < books.size(); i++) {
                WaiJianItemModel.delete(books.get(i));
            }
        } else {

            UtilsLog.e("CarActivity----本地数据库查询----空==");
        }

        getGET_ALL_ITEMList();
//endregion
        //河南地区  开始录像  按钮
        if (SharedPreferencesUtils.getHeNanVersion(instances)) {
            acCarWaijianLuxiangStart.setVisibility(View.VISIBLE);
        } else {
            acCarWaijianLuxiangStart.setVisibility(View.GONE);
        }
        if (SharedPreferencesUtils.getTianJinVersion(instances)) {
            if (!TextUtils.isEmpty(carsInforModel.getDetectDate())) {
                UtilsLog.e("DateUtil.currentTime2()==" + DateUtil.currentTime2());
                UtilsLog.e("carsInforModel.getDetectDate()==" + carsInforModel.getDetectDate());
                UtilsLog.e("carsInforModel.registerdate()==" + carsInforModel.getRegisteDate());

                /**
                 * 1、PDA手机外检获取车辆时，如果车辆注册登记日期大于2022年9月1日，
                 * 车型为轻型栏板货车、轻型厢式货车、轻型仓栅货车，提示查验员“请仔细核对车厢内部尺寸，宽度不能超过2100mm”；
                 * 如果车辆注册登记日期大于2022年9月1日，
                 * 车型为轻型自卸货车，提示查验员“请仔细核对车厢内部尺寸，宽度不能超过1800mm”
                 * */
                String str = carsInforModel.getRegisteDate().substring(6, carsInforModel.getRegisteDate().length() - 2).trim();
                String comparisonDate = "2022-09-01";
                String registerdate = DateUtil.getDateTimeFromMillisecond(Long.parseLong(str));
                String registerdateFormat = DateUtil.getDateForSurplus(registerdate);
                UtilsLog.e("registerdateFormat==" + registerdateFormat);
                register_date_result = DateUtil.isDateOneBigger(registerdateFormat, comparisonDate);//true:第一个大
                UtilsLog.e("result==" + register_date_result);

                int days = DateUtil.getDaysBetween2(DateUtil.currentTime2(), carsInforModel.getDetectDate());
                UtilsLog.e("days==" + days);
                if (days >= 1) {
                    TianJin_Start = true;
                } else {
                    TianJin_Start = false;
                }
            }
        } else {
            TianJin_Start = false;
        }
        UtilsLog.e("TianJin_Start==" + TianJin_Start);

        Line = SharedPreferencesUtils.getMoRenLine2(this) ? "2" : "1";
    }


    private void initMoreInfo() {
        isMoreInfo = false;
        acCarMoreInfo.setText("更多");
        acCarLayoutMoreInfo.setVisibility(View.GONE);
    }

    @Override
    protected void onResume() {
        super.onResume();
        List<WaiJianItemModel> waiJianItemModelList = WaiJianItemModel.find(WaiJianItemModel.class, "SN=?", carsInforModel.getSN());
        if (waiJianItemModelList != null && waiJianItemModelList.size() > 0) {
            UtilsLog.e("waiJianItemModelList=onResume==" + waiJianItemModelList.toString());
        } else {
            UtilsLog.e("waiJianItemModelList==onResume=null");
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        OkGo.getInstance().cancelTag(this);
        instances = null;
        BaseApplication.DZSS = "否";
        String logStrf = "\n" + "onDestroy-----车辆详情-----CarActivity---" + dzss + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
        List<WaiJianItemModel> books = WaiJianItemModel.listAll(WaiJianItemModel.class);
        if (books != null && books.size() > 0) {
            for (int i = 0; i < books.size(); i++) {
                WaiJianItemModel.delete(books.get(i));
            }
        }
        List<WaiJianItemModel> waiJianItemModelList = WaiJianItemModel.find(WaiJianItemModel.class, "SN=?", carsInforModel.getSN());
        if (waiJianItemModelList != null && waiJianItemModelList.size() > 0) {
            UtilsLog.e("waiJianItemModelList=onDestroy==" + waiJianItemModelList.toString());
            for (int i = 0; i < waiJianItemModelList.size(); i++) {
                WaiJianItemModel.delete(waiJianItemModelList.get(i));
            }
        } else {
            UtilsLog.e("waiJianItemModelList=onDestroy==null");
        }
    }

    @OnClick({R.id.ac_car_line, R.id.ac_car_lianwang,
            R.id.ac_car_weiyixing, R.id.ac_car_waijian,
            R.id.ac_car_6m, R.id.ac_car_waijian_luxiang_start,
            R.id.ac_car_lectronice_handbrake, R.id.ac_car_air_suspension,
            R.id.ac_car_suspension_form, R.id.ac_car_mileage,
            R.id.ac_car_btn_update, R.id.ac_car_more_info, R.id.ac_car_tv_beizhu_more, R.id.ac_car_waijian_update_infor
    })
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ac_car_waijian_update_infor:
                //更新车辆信息
                Line = acCarLine.getText().toString().trim();
                Intent up = new Intent(this, UpdateCarActivity.class);
                up.putExtra("model_CarsInforModel", carsInforModel);
                up.putExtra("Car_Line", Line);
                up.putExtra("login_w_name", Login_name);
                up.putExtra("login_IDNumber", login_IDNumber);
                startActivity(up);
                break;
            case R.id.ac_car_waijian_luxiang_start:
                //外检录像开始
                Line = acCarLine.getText().toString().trim();
                getDataWaiJainStart();
                break;
            case R.id.ac_car_6m:
                // 6米以上高度拍摄照片
                Line = acCarLine.getText().toString().trim();
                Intent i_12 = new Intent(this, Wai_6M_PhotoActivity.class);
                i_12.putExtra("model_CarsInforModel", carsInforModel);
                i_12.putExtra("Car_Line", Line);
                i_12.putExtra("login_w_name", Login_name);
                i_12.putExtra("login_IDNumber", login_IDNumber);
                i_12.putExtra("flag", 0);
                startActivity(i_12);
                break;
            case R.id.ac_car_line:
                //检测线号
                showMyDialog(line_str, R.id.ac_car_line);
                break;
            case R.id.ac_car_lianwang:
                Line = acCarLine.getText().toString().trim();
                if (TianJin_Start) {
                    TipDialog.show(this, "超24小时车辆无效信息", TipDialog.TYPE.WARNING);
                } else {
                    if (carsInforModel.getNQStatus().equals("0") && NQ_STATEMENT == false) {
                        Intent i_1 = new Intent(this, OnlineActivity.class);
                        i_1.putExtra("model_CarsInforModel", carsInforModel);
                        i_1.putExtra("Car_Line", Line);
                        i_1.putExtra("login_w_name", Login_name);
                        i_1.putExtra("login_IDNumber", login_IDNumber);
                        startActivityForResult(i_1, 101);
//                    startActivity(i_1);
                    } else {
                        MessageDialog.show(instances, "提示", "项目已经检测完成", "确定");
                    }
                }

                break;
            case R.id.ac_car_weiyixing:
                Line = acCarLine.getText().toString().trim();
                EngineNOFlag = acCarBeizhu.getText().toString().trim();
                jianyi= acCarJianYiEt.getText().toString().trim();
                LogUtils.e("CarActivity-EngineNOFlag==" + EngineNOFlag);
                String memoLog0 = "memoLog0------" + EngineNOFlag;
                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, memoLog0.getBytes());
                if (TianJin_Start) {
                    TipDialog.show(this, "超24小时车辆无效信息", TipDialog.TYPE.WARNING);
                } else {
                    if (carsInforModel.getUCStatus().equals("0") && UC_STATEMENT == false) {
                        Intent i_2 = new Intent(this, UniquenessActivity.class);
                        i_2.putExtra("model_CarsInforModel", carsInforModel);
                        i_2.putExtra("Car_Line", Line);
                        i_2.putExtra("login_w_name", Login_name);
                        i_2.putExtra("login_IDNumber", login_IDNumber);
                        i_2.putExtra("EngineNOFlag", EngineNOFlag);
                        startActivityForResult(i_2, 102);
//                    startActivity(i_2);
                    } else {
                        MessageDialog.show(instances, "提示", "项目已经检测完成", "确定");
                    }
                }

                break;
            case R.id.ac_car_waijian:
                Line = acCarLine.getText().toString().trim();
                EngineNOFlag = acCarBeizhu.getText().toString().trim();
                jianyi= acCarJianYiEt.getText().toString().trim();
                LogUtils.e("CarActivity-EngineNOFlag==" + EngineNOFlag);
                LogUtils.e("CarActivity-jianyi==" + jianyi);
                if (SharedPreferencesUtils.getTianJinVersion(instances)) {
                    if (carsInforModel.getItem() != null && carsInforModel.getItem().contains("F1")) {
                        UtilsLog.e("getItem===" + carsInforModel.getItem());
                        acCarWaijian.setEnabled(true);
                    } else {
                        acCarWaijian.setEnabled(false);
                        Toast.makeText(instances, "该车未发外检项目", Toast.LENGTH_LONG).show();
                    }
                    if (register_date_result) {
                        if (carsInforModel.getTypeName().contains("轻型栏板货车")
                                || carsInforModel.getTypeName().contains("轻型厢式货车") ||
                                carsInforModel.getTypeName().contains("轻型仓栅货车")) {
                            TipDialog.show(this,"请仔细核对车厢内部尺寸，宽度不能超过2100mm", TipDialog.TYPE.WARNING).setTipTime(4200);
                        } else if (carsInforModel.getTypeName().contains("轻型自卸货车")) {
                            TipDialog.show(this, "请仔细核对车厢内部尺寸，宽度不能超过1800mm", TipDialog.TYPE.WARNING).setTipTime(4200);
                        }
                    }

                    if (TianJin_Start) {
                        TipDialog.show(this, "超24小时车辆无效信息", TipDialog.TYPE.WARNING).setTipTime(3500);
                    } else {
                        acCarWaijian.setEnabled(true);
                        Intent i_3 = new Intent(this, WaiJianActivity.class);
                        i_3.putExtra("model_CarsInforModel", carsInforModel);
                        i_3.putExtra("Car_Line", Line);
                        i_3.putExtra("login_w_name", Login_name);
                        i_3.putExtra("login_IDNumber", login_IDNumber);
                        i_3.putExtra("EngineNOFlag", EngineNOFlag);
                        i_3.putExtra("jianyi", jianyi);
                        i_3.putExtra("dzss", BaseApplication.DZSS);
                        startActivity(i_3);
                    }
                } else {
                    acCarWaijian.setEnabled(true);
                    Intent i_3 = new Intent(this, WaiJianActivity.class);
                    i_3.putExtra("model_CarsInforModel", carsInforModel);
                    i_3.putExtra("Car_Line", Line);
                    i_3.putExtra("login_w_name", Login_name);
                    i_3.putExtra("login_IDNumber", login_IDNumber);
                    i_3.putExtra("EngineNOFlag", EngineNOFlag);
                    i_3.putExtra("jianyi", jianyi);
                    i_3.putExtra("dzss", BaseApplication.DZSS);
                    startActivity(i_3);
                }


//                if (!TextUtils.isEmpty(Item_Code)) {
//                    if (CHECK_MODE == 0) {
////                        getDataWaiJainStart("");
////                        String logStr = "车牌号码：：" + carsInforModel.getPlateRegion() + carsInforModel
////                                .getPlateNO() + "\n" + "动作：点击项目开始按钮";
////                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
//                    } else {
//
//                    }
//                }
                break;
            case R.id.ac_car_lectronice_handbrake:
                //是否为电子手刹
                String logStr = "\n" + "触发-----外检更新车辆信息----点击事件--是否为电子手刹" + "\n";
                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                showMyDialog(fou_shi_str, R.id.ac_car_lectronice_handbrake);
                break;
            case R.id.ac_car_air_suspension:
                //是否配备空气悬架
                showMyDialog(fou_shi_str, R.id.ac_car_air_suspension);
                break;
            case R.id.ac_car_suspension_form:
                //悬架形式
                showMyDialog(suspension_form, R.id.ac_car_suspension_form);
                break;
            case R.id.ac_car_btn_update:
                //更新车辆信息
                updateCarInfo();
                break;
            case R.id.ac_car_more_info:
                if (Integer.valueOf(carsInforModel.getTimes()) == 1 && carsInforModel != null) {
                    if (!isMoreInfo) {
                        isMoreInfo = true;
                        acCarMoreInfo.setText("隐藏");
                        acCarLayoutMoreInfo.setVisibility(View.VISIBLE);
                    } else {
                        initMoreInfo();
                    }
                }
                break;
            case R.id.ac_car_tv_beizhu_more:
                showMyDialog(more_str, R.id.ac_car_tv_beizhu_more);
                break;
        }

    }

    private String[] line_str = new String[]{"1", "2", "3", "4", "5", "6"};
    private String[] fou_shi_str = new String[]{"否", "是"};
    private String[] suspension_form = new String[]{"独立悬架", "非独立悬架"};
    private String[] more_str = new String[]{"无", "发动机标识缺失且打刻号码不易见,无法拍摄", "发动机号已查验核实但无法拍摄"};

    private void showMyDialog(String[] str, final int id) {
//        BottomMenu bottomMenu= BottomMenu().build(this);
        BottomMenu.show(this, str, new OnMenuItemClickListener() {
            @Override
            public void onClick(String text, int index) {
                //返回参数 text 即菜单名称，index 即菜单索引
                UtilsLog.e("外检---showMyDialog==" + text + "===" + index);
                switch (id) {
                    case R.id.ac_car_line:
                        // 线号
                        acCarLine.setText(text);
                        break;
                    case R.id.ac_car_air_suspension:
                        //空气悬架
                        acCarAirSuspension.setText(text);
                        break;
                    case R.id.ac_car_suspension_form:
                        //悬架类型
                        acCarSuspensionForm.setText(text);
                        break;
                    case R.id.ac_car_lectronice_handbrake:
                        //电子手刹
                        acCarLectroniceHandbrake.setText(text);
                        String logStr = "\n" + "触发-----选择弹出框--是否为电子手刹" + "\n"
                                + text;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        break;
                    case R.id.ac_car_tv_beizhu_more:
                        //备注
                        acCarBeizhu.setText(text);
                        break;
                }
            }
        }).setMenuTextInfo(new TextInfo().setBold(true).setFontColor(Color.BLACK).setGravity(Gravity.CENTER));
    }

    //更新车辆信息
    private void updateCarInfo() {
        String logStr_update = "\n" + "updateCarInfo-------是否为电子手刹" + "\n";
        String airSuspension = acCarAirSuspension.getText().toString().trim();
        String electronicHandbrake = acCarLectroniceHandbrake.getText().toString().trim();
        //空气悬架轴数
        String kongqi_xuanjia_zhou_shu = acCarKongqiXuanjiaZhouShu.getText().toString().trim();
        UtilsLog.e("空气悬架轴数=====" + kongqi_xuanjia_zhou_shu);
        String suspensionForm = acCarSuspensionForm.getText().toString().trim();
        if (!TextUtils.isEmpty(acCarMileage.getText().toString().trim())) {
            UpdateCarInfoModel uciModel = new UpdateCarInfoModel();

            if (!TextUtils.isEmpty(kongqi_xuanjia_zhou_shu)) {
                uciModel.setAirSuspensionAxle(kongqi_xuanjia_zhou_shu);
            } else {
                uciModel.setAirSuspensionAxle("");
            }
            model.setKongqiXuanjiaZhou(kongqi_xuanjia_zhou_shu);
            if (airSuspension.equals("否")) {
                uciModel.setAirSuspension("2");//空气悬架
                model.setKongqiXuanjia("否");
            } else {
                uciModel.setAirSuspension("1");//空气悬架
                model.setKongqiXuanjia("是");
            }
            if (electronicHandbrake.equals("否")) {
                uciModel.setElectronicHandbrake("2");//电子手刹
                model.setShifouDianzikongzhi("2");
            } else {
                uciModel.setElectronicHandbrake("1");//电子手刹
                model.setShifouDianzikongzhi("1");
            }
            if (electronicHandbrake.contains("是")) {
                BaseApplication.DZSS = "是";
                dzss = "是";
                model.setShifouDianzikongzhi("是");
            } else {
                BaseApplication.DZSS = "否";
                dzss = "否";
                model.setShifouDianzikongzhi("否");
            }
            logStr_update += "electronicHandbrake::" + electronicHandbrake + "\n" +
                    "dzss::" + dzss + "uciModel.getElectronicHandbrake==" + uciModel.getElectronicHandbrake() + "\n";
            PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr_update.getBytes());
            UtilsLog.e("=====" + logStr_update);
            if (suspensionForm.equals("独立悬架")) {
                uciModel.setSuspensionForm("0");//悬架形式
                uciModel.setSuspensionType("0");
                model.setXuanjia_xingshi("独立悬架");
            } else {
                uciModel.setSuspensionForm("1");//悬架形式
                uciModel.setSuspensionType("1");
                model.setXuanjia_xingshi("非独立悬架");
            }
            uciModel.setOdometer(acCarMileage.getText().toString().trim());//里程表读数
            model.setOther_1(acCarMileage.getText().toString().trim());

            uciModel.setPlatformSN(carsInforModel.getPlatformSN());
            uciModel.setPlateType(carsInforModel.getPlateType());
//            uciModel.setPlateNO(carsInforModel.getPlateRegion() + carsInforModel.getPlateNO());
            uciModel.setPlateRegion(carsInforModel.getPlateRegion());
            uciModel.setPlateNO(carsInforModel.getPlateNO());
            uciModel.setVIN(carsInforModel.getVIN());
            uciModel.setIsSafe("1");
            uciModel.setCarType(carsInforModel.getType());
            uciModel.setType(carsInforModel.getType());
            uciModel.setApprovedLoad(carsInforModel.getApprovedLoad());
            uciModel.setCategory(carsInforModel.getCategory());
            uciModel.setCurbWeight(carsInforModel.getCurbWeight());
            String str = carsInforModel.getProductionDate().substring(6, carsInforModel.getProductionDate().length() - 2).trim();
            String registerdate = DateUtil.getDateTimeFromMillisecond(Long.parseLong(str));
            String registerdateFormat = DateUtil.getDateForSurplus(registerdate);
            uciModel.setProductionDate(registerdateFormat);
            uciModel.setTotalMass(carsInforModel.getTotalMass());
            uciModel.setUseProperty(carsInforModel.getUseProperty());
            uciModel.setHeadlightSystem(carsInforModel.getHeadlightSystem());
            uciModel.setUnderpanType(carsInforModel.getUnderpanType());
            uciModel.setTotalAxis(carsInforModel.getTotalAxis());
            uciModel.setDetectCategroy(carsInforModel.getDetectionCategory());
            uciModel.setQIsSingle(carsInforModel.getQIsSingle());
            uciModel.setQueueID(carsInforModel.getQueueID());
            uciModel.setVehicleID(carsInforModel.getVehicleID());
            uciModel.setEngineNO(carsInforModel.getEngineNO());
            uciModel.setBodyColor(carsInforModel.getBodyColor());
            uciModel.setValidTill(carsInforModel.getValidTill());
            uciModel.setExpirationDate(carsInforModel.getExpirationDate());
            uciModel.setFuelType(carsInforModel.getFuelType());
            uciModel.setBrand(carsInforModel.getBrand());
            uciModel.setCarModel(carsInforModel.getCarModel());
            uciModel.setProductionEnterprises(carsInforModel.getProductionEnterprises());
            uciModel.setOwner(carsInforModel.getOwner());
            uciModel.setVehicleType(carsInforModel.getVehicleType());
            uciModel.setUsage(carsInforModel.getUsage());
            uciModel.setUseAttribute(carsInforModel.getUseAttribute());
            uciModel.setLicense(carsInforModel.getLicense());
            uciModel.setParkingAxle(carsInforModel.getParkingAxle());
            uciModel.setBrakeForce(carsInforModel.getBrakeForce());
            uciModel.setParallelModel(carsInforModel.getParallelModel());
            uciModel.setPower(carsInforModel.getPower());
            uciModel.setParkingAxis(carsInforModel.getParkingAxis());
            uciModel.setMainAxis(carsInforModel.getMainAxis());
            uciModel.setCentralAxle(carsInforModel.getCentralAxle());

            //本地数据库保存，电子手刹，里程数，空气悬架，悬架形式
            model.setCar_no(carsInforModel.getPlateRegion() +
                    carsInforModel.getPlateNO());
            model.setSN(carsInforModel.getSN());
            model.setOther_2("1");
            //转向轴数量
            if (!TextUtils.isEmpty(String.valueOf(carsInforModel.getTurnAxis()))) {
                model.setZhuanxiangzhou(carsInforModel.getTurnAxis());
            } else {
                model.setZhuanxiangzhou("1");
            }
            model.save();
            Gson gson = new Gson();
            String jsonStr = gson.toJson(uciModel);
            String upjson_url = "{" + jsonStr.substring(1, jsonStr.length() - 1) + "}";

            String logStr = "\n" + "外检更新车辆信息----json" + "\n" +
                    "json::" + upjson_url + "\n" + "electronicHandbrake::" + electronicHandbrake + "\n" +
                    "URL::" + SharedPreferencesUtils.getIP(instances) + UPDATE_VEHICLE_INFO + "\n" +
                    "model::" + model.toString() + "\n";
            PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
            UtilsLog.e("外检更新车辆信息---jsonStr==" + upjson_url);
            UtilsLog.e("外检更新车辆信息---BaseApplication.DZSS==" + BaseApplication.DZSS);
            UtilsLog.e("外检更新车辆信息---url==" + SharedPreferencesUtils.getIP(this) + UPDATE_VEHICLE_INFO);
            OkGo.<String>post(SharedPreferencesUtils.getIP(this) + UPDATE_VEHICLE_INFO)
                    .tag(this)
                    .upJson(jsonStr)
                    .execute(new StringCallback() {
                        @Override
                        public void onStart(Request<String, ? extends Request> request) {
                            super.onStart(request);
                            CommonUtils.showLoadingDialog(instances, "加载中...");
                        }

                        @Override
                        public void onSuccess(Response<String> response) {
                            CommonUtils.hideLoadingDialog(instances);
                            String result = response.body().trim();
                            UtilsLog.e("外检更新车辆信息-result==" + result);
                            UtilsLog.e("外检更新车辆信息-result=22=" + result.substring(1, result.length() -
                                    1));
                            String logStr = "\n" + "外检更新车辆信息----请求成功" + "\n" +
                                    "result::" + response.body() + "\n" +
                                    "URL::" + SharedPreferencesUtils.getIP(instances) + UPDATE_VEHICLE_INFO;
                            PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                            CommonUtils.hideLoadingDialog(instances);
                            String str = result.substring(1, result.length() - 1);
                            if (!TextUtils.isEmpty(result) && !"[[]]".equals(result) && !"[{}]".equals(result)
                                    && !"[]".equals(result)) {
                                String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\",
                                        "");
                                UtilsLog.e("getDataUploadPhoto-newResult==" + newResult);
                                if ("ok".equalsIgnoreCase(newResult)) {
                                    Toast.makeText(instances, "更新车辆信息成功", Toast.LENGTH_LONG).show();
                                } else {
                                    Toast.makeText(instances, "更新车辆信息失败", Toast.LENGTH_SHORT).show();
                                }
                            }
                        }

                        @Override
                        public void onError(Response<String> response) {
                            super.onError(response);
                            CommonUtils.hideLoadingDialog(instances);
                            String logStr2 = "\n" + "外检更新车辆信息--onError" + "\n" +
                                    "result::" + response.body();
                            PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
                            UtilsLog.e("外检更新车辆信息-onError==" + response.body());
                            CommonUtils.hideLoadingDialog(instances);
                            Toast.makeText(instances, "更新车辆信息失败", Toast.LENGTH_LONG).show();
                        }
                    });
        } else {
            Toast.makeText(instances, "里程数不能为空", Toast.LENGTH_SHORT).show();
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data != null) {
            UtilsLog.e("onActivityResult=resultCode=" + resultCode);
            UtilsLog.e("onActivityResult==" + data.getIntExtra("nq", 0));
            switch (resultCode) {
                case 101:
                    int result_1 = data.getIntExtra("nq", 0);
                    if (result_1 == 1) {
                        NQ_STATEMENT = true;
                    } else {
                        NQ_STATEMENT = false;
                    }
                    break;
                case 102:
                    int result_2 = data.getIntExtra("nq", 0);
//                    EngineNOFlag = data.getStringExtra("EngineNOFlag");
//                    if (!TextUtils.isEmpty(EngineNOFlag)){
//                        carsInforModel.setEngineNOFlag(EngineNOFlag);
//                    }
                    if (result_2 == 1) {
                        UC_STATEMENT = true;
                    } else {
                        UC_STATEMENT = false;
                    }
                    break;
            }
        }
    }


    //获取所有人工检验项目接口
    private void getGET_ALL_ITEMList() {
        String url = "";
//        if (SharedPreferencesUtils.get38900(instances)) {
        url = GET_ALL_ITEM38900;
//        } else {
//            url = GET_ALL_ITEM;
//        }
        String logStr = "\n" + "获取所有人工检验项目接口----" + "\n" + "URL::" +
                SharedPreferencesUtils.getIP(instances) +
                url + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        UtilsLog.e("getGET_ALL_ITEMList---url==" + SharedPreferencesUtils.getIP(instances) + url);
        OkGo.<String>get(SharedPreferencesUtils.getIP(instances) + url).tag(instances)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
//                        CommonUtils.hideLoadingDialog(instances);
                        String result = response.body();
//                        UtilsLog.e("getGET_ALL_ITEMList-result==" + result);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("getGET_ALL_ITEMList-newResult==" + newResult);
//                        String logStr = "\n" + "获取所有人工检验项目接口----onSuccess" + "\n" + "result::" + response.body() + "\n";
//                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(result)) {
                            checkItemModelList = new ArrayList<CheckItemModel>();
                            checkItemModelList = JsonUtil.stringToArray(newResult, CheckItemModel[].class);
//                            for (int i = 0; i < checkItemModelList.size(); i++) {
//                                UtilsLog.e("checkItemModelList=11=" + checkItemModelList.get(i).toString());
//                            }

                        } else {
//                            Toast.makeText(instances, getResources().getString(R.string.network_error),
// Toast.LENGTH_LONG).show();
                            UtilsLog.e("getGET_ALL_ITEMList-result==" + "没有数据");
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
//                        CommonUtils.hideLoadingDialog(instances);
                        UtilsLog.e("getGET_ALL_ITEMList-onError==" + response.body());
                        String logStr = "\n" + "获取所有人工检验项目接口----onError" + "\n" + "result::" + response.body() + "\n";
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        Toast.makeText(CarActivity.this, getResources().getString(R.string.services_error), Toast
                                .LENGTH_LONG).show();
                    }
                });
    }

    //外检开始
    private void getDataWaiJainStart() {
        CarItemStartModel carItemStartModel = new CarItemStartModel();
        carItemStartModel.setPlatformSN(carsInforModel.getPlatformSN());
        carItemStartModel.setPlateType(carsInforModel.getPlateType());
        carItemStartModel.setPlateNO(carsInforModel.getPlateRegion() + carsInforModel.getPlateNO());
        carItemStartModel.setVIN(carsInforModel.getVIN());
        carItemStartModel.setDetectionID(String.valueOf(carsInforModel.getID()));
        carItemStartModel.setLine(Line);
        carItemStartModel.setTest_times(carsInforModel.getTimes());
        carItemStartModel.setDetectionDevID(SharedPreferencesUtils.getIMEI(instances));
        carItemStartModel.setItemCode("F1");
        BaseApplication.W_ItemStart_time = "";
        BaseApplication.W_ItemStart_time = DateUtil.currentTime2();
        carItemStartModel.setDetectionItemStartDate(BaseApplication.W_ItemStart_time);
        Gson gson = new Gson();
        String jsonStr = gson.toJson(carItemStartModel);
        String upjson_url = "{" + jsonStr.substring(1, jsonStr.length() - 1) + "}";

        String logStr = "\n" + "外检录像开始按钮----json" + "\n" +
                "json::" + upjson_url + "\n" +
                "URL::" + SharedPreferencesUtils.getIP(instances) + ITEM_START;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        UtilsLog.e("外检录像开始按钮---jsonStr==" + upjson_url);
        UtilsLog.e("外检录像开始按钮---url==" + SharedPreferencesUtils.getIP(this) + ITEM_START);
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + ITEM_START)
                .tag(this)
                .upJson(upjson_url)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body().trim();
                        UtilsLog.e("外检录像开始按钮-result==" + result);
                        UtilsLog.e("外检录像开始按钮-result=22=" + result.substring(1, result.length() -
                                1));
                        String logStr = "\n" + "外检录像开始按钮----请求成功" + "\n" +
                                "result::" + response.body() + "\n" +
                                "URL::" + SharedPreferencesUtils.getIP(instances) + ITEM_START;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                        String str = result.substring(1, result.length() - 1);
                        Toast.makeText(instances, "外检录像开始", Toast.LENGTH_LONG).show();
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        String logStr2 = "\n" + "外检录像开始按钮--onError" + "\n" +
                                "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
                        UtilsLog.e("外检录像开始按钮-onError==" + response.body());
                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }

}
